﻿var Colorbox4Sitecore = window.Colorbox4Sitecore || {};

Colorbox4Sitecore.initColorbox = function (config) {
    /* Initalize the configuration */
    var colorboxConfig = {        
        transition : config.transition,
        speed : config.speed,
        scalePhotos : config.scalePhotos,
        scrolling : config.scrolling,

        href : config.href,
        title : config.title,
        rel : config.rel,
        current : config.current,
        previous : config.previous,
        next : config.next,
        close : config.close,
        xhrError : config.xhrError,
        imgError : config.imgError,

        opacity : config.opacity,
        open : config.open,
        returnFocus : config.returnFocus,
        fastIframe : config.fastIframe,
        preloading : config.preloading,
        overlayClose : config.overlayClose,
        escKey : config.escKey,
        arrowKey : config.arrowKey,
        loop : config.loop,
        data : config.data,

        iframe : config.iframe,
        inline : config.inline,
        html : config.html,
        photo : config.photo,

        width : config.width,
        height : config.height,
        innerWidth : config.innerWidth,
        innerHeight : config.innerHeight,
        initialWidth : config.initialWidth,
        maxWidth : config.maxWidth,
        maxHeight: config.MaxHeight,

        slideshow : config.slideshowEnable,
        slideshowSpeed : config.slideshowSpeed,
        slideshowAuto : config.slideshowAuto,
        slideshowStartText : config.slideshowStartText,
        slideshowEndText : config.slideshowEndText,

        fixed : config.fixed,
        top : config.top,
        bottom : config.bottom,
        left : config.left,
        right : config.right,
    };

    if(config.slideshowEnable) { //Bugfix to allow an external link to open the slideshow
        var gallery = $("a[rel='pics_" + config.selector + "']").colorbox(colorboxConfig);
		$("a." + config.selector).click(function(e){
			e.preventDefault();
			gallery.eq(0).click();
		});
    }
    else {
        //$("a." + config.selector).attr('href', config.href);

        //Call the colorbox plugin
        $('.' + config.selector).colorbox(colorboxConfig);
    }
}